package com.m3958.firstgwt.server.dao;

import java.util.List;

import javax.persistence.Query;

import com.google.inject.Inject;
import com.m3958.firstgwt.server.model.BaseModel;
import com.m3958.firstgwt.server.model.WFChangeLog;

public class WFChangeLogDao  extends BaseDao<WFChangeLog>{
	
	@Inject
	public WFChangeLogDao(WFChangeLogChangeStrategy task) {
		super(WFChangeLog.class);
		extraStrategyTask = task;
	}
	
	
	public int getUserLastTransLogId(){
		int uid = getReqPs().getRelationModelId();
		Query q = emp.get().createNamedQuery(WFChangeLog.NamedQueries.FIND_USER_LAST_LOG);
		q.setFirstResult(0);
		q.setMaxResults(1);
		q.setParameter(1, uid);
		List<WFChangeLog> wfcl = q.getResultList();
		int wfcid = 0;
		if(wfcl.size() == 1){
			wfcid = wfcl.get(0).getId();
		}
		return wfcid;
	}
	
	public int getItemLastTransLogId(){
		String itemId = getReqPs().getStringValue("mid");
		Query q = emp.get().createNamedQuery(WFChangeLog.NamedQueries.FIND_ITEM_LAST_LOG);
		q.setFirstResult(0);
		q.setMaxResults(1);
		q.setParameter(1, "%" + itemId + "%");
		List<WFChangeLog> wfcl = q.getResultList();
		int wfcid = 0;
		if(wfcl.size() == 1){
			wfcid = wfcl.get(0).getId();
		}
		return wfcid;
	}

	
	@Override
	public Integer smartCustomCount() {
		return 0;
	}

	@Override
	public List<BaseModel> smartCustomFetch() {
		return null;
	}


	@Override
	public List<WFChangeLog> smartNamedQueryFetch() {
		return null;
	}


	@Override
	public Integer smartNamedQueryFetchCount() {
		return null;
	}

}
